package com.frank.jpaBatchSave.web;

import com.frank.jpaBatchSave.entity.Person;
import com.frank.jpaBatchSave.entity.Student;
import com.frank.jpaBatchSave.repository.PersonRepository;
import com.frank.jpaBatchSave.repository.Student1Repository;
import com.frank.jpaBatchSave.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author 小石潭记
 * @date 2020/11/23 16:59
 * @Description: ${todo}
 */
@Slf4j
@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonRepository repository;

    @Autowired
    private Student1Repository student1Repository;

    @Autowired
    private UserService userService;

    @GetMapping
    public Object index() {
        List<Integer> ids = new ArrayList<>();
        ids.add(1);
        ids.add(2);
        ids.add(3);
        Optional<Person> person = repository.deleteById(1);
        System.out.println(person);
        return person;
//        return repository.findAllById(ids);
        /*Optional<Person> byId = repository.findById(1);
        Person person = byId.get();
        person.setName("66666");*/
//        return repository.findAll(PageRequest.of(0, 2));
        /*Optional<Integer> minAge = repository.findMinAge();
        log.info("查询的最小的年纪,{}", minAge.isPresent() ? minAge.get() : 0);
        return repository.getAllPerson();*/
    }


    @GetMapping("/student")
    public Object get() {
        Iterable<Student> all = student1Repository.findAll();
        userService.updateStudent();
        Iterable<Student> all1 = student1Repository.findAll();
        return all1;
    }
}
